package org.es.eventbus;

/**
 * Copyright (C) 2012 Eduard Sedov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import org.es.eventbus.DeadEvent;
import org.es.eventbus.DeadTopicEvent;
import org.es.eventbus.EventBus;
import org.es.eventbus.EventListener;
import org.es.eventbus.TopicListener;

/**
 *
 * @author Sedov Eduard
 */
public class Main {

    public static void main(String[] args) {
        EventListener eventListener = new EventListener() {

            @Override
            public void onEvent(Object event) {
//				System.out.println(event);
            }
        };

        TopicListener topicListener = new TopicListener() {

            @Override
            public void onEvent(String topic, Object event) {
//				System.out.println(topic + ":" + event);
            }
        };



        EventBus.get().subscribeStrong(String.class, eventListener);
        EventBus.get().subscribeStrong(DeadEvent.class, eventListener);
        EventBus.get().subscribeStrong(DeadTopicEvent.class, eventListener);
        EventBus.get().subscribeStrong("topic", topicListener);

        System.gc();


        EventBus.get().publish("test");
        EventBus.get().publish(1);
        EventBus.get().publish("topic", "topic_Msg");
        EventBus.get().publish("topic2", "topic2_Msg");

        long start = System.currentTimeMillis();

        for (int i = 0; i < 1000000; i++) {
            EventBus.get().publish("test");
            EventBus.get().publish(1);
            EventBus.get().publish("topic", "topic_Msg");
            EventBus.get().publish("topic2", "topic2_Msg");
        }

        System.out.println("Tok in " + (System.currentTimeMillis() - start) + " ms.");

        EventBus.get().unsubscribe(String.class, eventListener);
        EventBus.get().unsubscribe(DeadEvent.class, eventListener);
        EventBus.get().unsubscribe(DeadTopicEvent.class, eventListener);
        EventBus.get().unsubscribe("topic", topicListener);

    }
}
